<#import "../template.ftl" as t/>
<@t.html ; part>
    <#if part="head">
        <link href="<@spring.url "/resources/plugins/datatables/dataTables.bootstrap.css"/>" rel="stylesheet">
        <link href="<@spring.url "/resources/plugins/datatables/responsive.dataTables.min.css"/>" rel="stylesheet">
        <link href="<@spring.url "/resources/plugins/bootstrap-select/bootstrap-select.min.css"/>" rel="stylesheet">
    </#if>
    <#if part="body">
        <div class="panel">
            <div class="panel-heading">
                <h3 class="panel-title"></h3>
            </div>
            <div class="panel-body">
                <div class="pad-btm form-inline">
                    <div class="row">
                        <div class="col-sm-6 table-toolbar-left">
                            <button id="demo-btn-addrow" class="btn btn-purple" onclick="addSale()"><i class="demo-pli-add"></i> 添加销售/代理</button>
                        </div>
                        <div class="col-sm-6 table-toolbar-right">
                        </div>
                    </div>
                </div>
                <table id="dt-basic" class="table table-striped table-bordered"
                       cellspacing="0" width="100%">
                    <thead>
                    <tr>
                        <th>姓名</th>
                        <th>手机号码</th>
                        <th class="min-tablet">类别</th>
                        <th class="min-desktop">操作</th>
                    </tr>
                    </thead>
                    <tbody>
            <#if userList?? && (userList?size>0)>
                <#list userList as user>
                    <tr>
                        <td>${user.name}</td>
                        <td>${user.phone}</td>
                        <td><#if user.types==3>销售<#else >代理</#if></td>
                        <td>
                            <button id="demo-btn-addrow" class="btn btn-info" onclick="window.location.href='<@spring.url "/manage/dataSetting/showData/${user.id}"/>'">设置数据查询权限</button>
                            <button id="demo-btn-addrow" class="btn btn-info" onclick="deleteUser(${user.id})">删除</button>
                        </td>
                    </tr>
                </#list>
            </#if>
                    </tbody>
                </table>
            </div>
        </div>

    </#if>
    <#if part="modal">
        <div class="modal fade" id="userData" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog modal-lg" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title">添加销售</h4>
                    </div>
                    <div class="modal-body">
                        <div class="panel-body">
                            <form class="panel-body form-horizontal form-padding">
                                <div class="form-group">
                                    <label class="col-md-3 control-label" for="demo-text-input">姓名</label>
                                    <div class="col-md-6">
                                        <input type="text" id="newName" name="newName" value="" class="form-control" placeholder="">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label" for="demo-text-input">手机号码</label>
                                    <div class="col-md-6">
                                        <input type="text" id="newPhone" name="newPhone" value="" class="form-control" placeholder="">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label" for="demo-text-input">类型</label>
                                    <div class="col-md-6">
                                        <select class="selectpicker" id="newTypes" name="newTypes" tabindex="2">
                                            <option value="3">销售</option>
                                            <option value="4">代理</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label" for="demo-text-input"></label>
                                    <div class="col-md-6">
                                        <button type="button" class="btn btn-success" onclick="saveInfo()">保存</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <div class="modal-footer">
                    </div>
                </div>
            </div>
        </div>
    </#if>

    <#if part="foot_script">
        <script src="<@spring.url "/resources/plugins/datatables/jquery.dataTables.js"/>"></script>
        <script src="<@spring.url "/resources/plugins/datatables/dataTables.bootstrap.js"/>"></script>
        <script src="<@spring.url "/resources/plugins/datatables/dataTables.responsive.min.js"/>"></script>
        <script src="<@spring.url "/resources/plugins/bootstrap-select/bootstrap-select.min.js"/>"></script>
        <script src="<@spring.url "/resources/js/tables-datatables.js"/>"></script>
        <script type="text/javascript">
            //$(document).ready( function() {
            $('#dt-basic').dataTable( {
                "fnDrawCallback":function (settings) {
                    //$("#dt-basic thead tr th:first").removeClass("sorting_asc");
                    //$("#dt-basic tbody tr td:first").removeClass("sorting_asc");
                }
            });
            //});

            function addSale() {
                $("#userData").modal("show");
            }

            function saveInfo() {
                var name = $.trim($("#newName").val());
                if (name == null || name == "") {
                    alert("请输入销售姓名。");
                    return false;
                }
                var phone = $.trim($("#newPhone").val());
                if (phone == null || phone == "") {
                    alert("请输入销售手机号码。");
                    return false;
                }
                var types = $("#newTypes").val();
                $.post("<@spring.url "/manage/dataSetting/createSale"/>",{
                    name:name, phone:phone, types:types}, function (data) {
                    if (data.code==1) {
                        window.location.reload();
                    }
                });

            }

            function deleteUser(userId) {
                $.post("<@spring.url "/manage/dataSetting/deleteSale"/>",{
                    userId:userId}, function (data) {
                    alert(data.message);
                    if (data.code==1) {
                        window.location.reload();
                    }
                });
            }
        </script>


    </#if>
</@t.html>